package com.sky.mapper;

import com.sky.anno.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface DishMapper {
    List<DishVO> page(DishPageQueryDTO dishPageQueryDTO);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into dish(category_id, name, price, status, description, image, create_time, update_time, create_user, update_user) values(#{categoryId}, #{name}, #{price}, #{status}, #{description}, #{image}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    void save(Dish dish);

    @AutoFill(OperationType.UPDATE)
    @Update("update dish set status=#{status},update_time=#{updateTime},update_user=#{updateUser} where id=#{id}")
    void startOrStop(Dish dish);

    DishVO getById(Long id);

    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);

    List<DishVO> list(Long categoryId);

    void delete(List<Long> ids);
}
